package com.yxjwzpx.management.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.yxjwzpx.management.domain.FaultType;
import com.yxjwzpx.management.service.IFaultTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 故障类型管理Controller
 * 
 * @author yxjwzpx
 * @date 2025-04-08
 */
@RestController
@RequestMapping("/management/faulttype")
public class FaultTypeController extends BaseController
{
    @Autowired
    private IFaultTypeService faultTypeService;

    /**
     * 查询故障类型管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:faulttype:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaultType faultType)
    {
        startPage();
        List<FaultType> list = faultTypeService.selectFaultTypeList(faultType);
        System.out.println("查询故障类型成功！");
        return getDataTable(list);
    }

    /**
     * 导出故障类型管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:faulttype:export')")
    @Log(title = "故障类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaultType faultType)
    {
        List<FaultType> list = faultTypeService.selectFaultTypeList(faultType);
        ExcelUtil<FaultType> util = new ExcelUtil<FaultType>(FaultType.class);
        util.exportExcel(response, list, "故障类型管理数据");
    }

    /**
     * 获取故障类型管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:faulttype:query')")
    @GetMapping(value = "/{faultTypeId}")
    public AjaxResult getInfo(@PathVariable("faultTypeId") Long faultTypeId)
    {
        return success(faultTypeService.selectFaultTypeByFaultTypeId(faultTypeId));
    }

    /**
     * 新增故障类型管理
     */
    @PreAuthorize("@ss.hasPermi('management:faulttype:add')")
    @Log(title = "故障类型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaultType faultType)
    {
        return toAjax(faultTypeService.insertFaultType(faultType));
    }

    /**
     * 修改故障类型管理
     */
    @PreAuthorize("@ss.hasPermi('management:faulttype:edit')")
    @Log(title = "故障类型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaultType faultType)
    {
        return toAjax(faultTypeService.updateFaultType(faultType));
    }

    /**
     * 删除故障类型管理
     */
    @PreAuthorize("@ss.hasPermi('management:faulttype:remove')")
    @Log(title = "故障类型管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{faultTypeIds}")
    public AjaxResult remove(@PathVariable Long[] faultTypeIds)
    {
        return toAjax(faultTypeService.deleteFaultTypeByFaultTypeIds(faultTypeIds));
    }
}
